<?php
$con = mysql_connect("localhost","root","root");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("faithwar", $con);
date_default_timezone_set("PRC"); //timezone
#$dateTime = date("Y-m-d",strtotime("-1 day"));
$dateTime = date("Y-m-d");
#$dateTime = '2012-03-28';
  $deviceid_query = mysql_query("select  DISTINCT deviceid,logDate,date from tbheartbeat where date = '$dateTime' GROUP BY deviceid"); //id
    //$deviceid = mysql_fetch_array($deviceid_query);
    //while($deviceid[deviceid])

while($deviceid = mysql_fetch_array($deviceid_query))
{


  mysql_query("INSERT INTO deviceid (logDate,date,deviceid) VALUES ('$deviceid[logDate]','$deviceid[date]','$deviceid[deviceid]')");
}

mysql_close($con);
?>